﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetMyTaskDetail : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            MyTaskDetailOutParam result = new MyTaskDetailOutParam();
            MyTaskDetailInParam param = new MyTaskDetailInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as MyTaskDetailInParam;
                if (string.IsNullOrEmpty(param.user_id) || string.IsNullOrEmpty(param.todo_id) || string.IsNullOrEmpty(param.todo_rel_id))
                {
                    result.code = "0";
                    result.desc = "用户ID,关系ＩＤ,以及待办ID不能为空";

                    isFlag = false;
                }


                if (CommonUtils.IsDisableUsers(param.user_id))
                {
                    result.code = "0";
                    result.desc = "用户状态有问题，请联系管理员";

                    isFlag = false;
                }
                if(isFlag)
                {
                    //获取待办信息
                    DataSet dsTask = InterfaceHelper.GetPartyTaskByID(param.todo_id, param.todo_rel_id);

                    if (dsTask == null || dsTask.Tables[0].Rows.Count == 0)
                    {
                        result.code = "0";
                        result.desc = "待办不存在";

                        isFlag = false;
                    }
                    else if(dsTask.Tables[0].Rows[0]["RelationID"].ToString() != param.todo_rel_id.Trim())
                    {
                        result.code = "0";
                        result.desc = "该关系ID不属于该待办";

                        isFlag = false;
                    }
                    else
                    {
                        result.data.organiser = dsTask.Tables[0].Rows[0]["userName"].ToString();
                        result.data.start_time = dsTask.Tables[0].Rows[0]["CreateTime"].ToString();
                        result.data.title = dsTask.Tables[0].Rows[0]["Title"].ToString(); 

                        string category = dsTask.Tables[0].Rows[0]["category"].ToString();
                        if (category == "普通党课" || category == "视频党课" || category == "掌上党课")
                        {
                            result.data.type = "1";
                        }
                        else if (category == "普通会议" || category == "视频会议" || category == "掌上会议")
                        {
                            result.data.type = "2";
                        }
                        else if (category == "普通活动" || category == "视频活动" || category == "掌上活动" || category == "支部活动")
                        {
                            result.data.type = "3";
                        }
                        else if (category == "志愿活动")
                        {
                            result.data.type = "4";
                        }
                        else
                        {
                            result.code = "0";
                            result.desc = "该待办的类型不正确";

                            isFlag = false;
                        }
                    }
                }

                if (isFlag)
                {
                    //获取待办关联表详细信息
                    DataSet dsDetail = InterfaceHelper.GetPartyTaskDetail(result.data.type, param.todo_rel_id.Trim(), param.user_id);
                    if (dsDetail != null && dsDetail.Tables[0].Rows.Count > 0)
                    {
                        //result.data.actors = SXT.Utility.Business.Picker.GetPickerText("tblPartyOrgMembers", "UserName", "LoginID", dsDetail.Tables[0].Rows[0]["actors"].ToString());
                        
                        result.data.content = dsDetail.Tables[0].Rows[0]["content"].ToString();
                        result.data.meeting_addr = dsDetail.Tables[0].Rows[0]["meeting_addr"].ToString();
                        result.data.meeting_time = dsDetail.Tables[0].Rows[0]["meeting_time"].ToString();
                        result.data.act_status = dsDetail.Tables[0].Rows[0]["act_status"].ToString();
                        if (result.data.type == "4")
                        {
                            if (!string.IsNullOrEmpty(result.data.act_status) && result.data.act_status != "0")
                                result.data.act_status = "1";
                            else
                                result.data.act_status = "0";
                            DataSet dsMember = InterfaceHelper.GetPartyVSActivityMembers(param.todo_rel_id.Trim());
                            if (dsMember != null && dsMember.Tables[0].Rows.Count > 0)
                            {
                                for (int i = 0; i < dsMember.Tables[0].Rows.Count; i++)
                                {
                                    if (i == (dsMember.Tables[0].Rows.Count - 1))
                                    {
                                        result.data.actors += dsMember.Tables[0].Rows[i]["UserName"].ToString();
                                    }
                                    else
                                    {
                                        result.data.actors += dsMember.Tables[0].Rows[i]["UserName"].ToString() + ",";
                                    }
                                }
                            } 
                        }
                        else
                        {
                            result.data.actors = SXT.Utility.Business.Picker.GetUserPickerText(dsDetail.Tables[0].Rows[0]["actors"].ToString());
                        }
                    } 
                    else
                    {
                        result.code = "0";
                        result.desc = "该关系ID对应的记录不存在";

                        isFlag = false;
                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetMyTaskDetail", SerializeHelper.JsonSerializer<MyTaskDetailInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<MyTaskDetailInParam, MyTaskDetailOutParam>();
            else
                SafeProcessRequest<MyTaskDetailInParam, MyTaskDetailOutParam>();
        }
    }

    #region 请求参数
    public class MyTaskDetailInParam
    {
        /// <summary>
        /// 必填 用户ID
        /// </summary>
        public string user_id
        { get; set; }

        /// <summary>
        /// 必填 待办ID
        /// </summary>
        public string todo_id
        { get; set; } 

        /// <summary>
        /// 必填 关系ＩＤ 
        /// </summary>
        public string todo_rel_id
        { get; set; }  
    }
    #endregion

    #region 结果参数
    public class MyTaskDetailOutParam
    {
        public MyTaskDetailOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new MyTaskDetail();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 待办详情信息
        /// </summary>
        public MyTaskDetail data
        { get; set; }
    } 

    /// <summary>
    /// 待办详情信息
    /// </summary>
    public class MyTaskDetail
    {
        /// <summary>
        ///	待办标题	 
        /// </summary>
        public string title
        { get; set; }

        /// <summary>
        ///	待办类型 1：党课，2：会议,3:支部活动，4：志愿活动	 
        /// </summary>
        public string type
        { get; set; }

        /// <summary>
        ///	发起人	 
        /// </summary>
        public string organiser
        { get; set; }

        /// <summary>
        ///	发起时间	 
        /// </summary>
        public string start_time
        { get; set; }

        /// <summary>
        ///	会议/党课时间	 
        /// </summary>
        public string meeting_time
        { get; set; }

        /// <summary>
        ///	会议/党课地点	 
        /// </summary>
        public string meeting_addr
        { get; set; }

        /// <summary>
        ///	待办内容	 
        /// </summary>
        public string content
        { get; set; }

        /// <summary>
        ///	参与人员 多个参与人之间以英文分号分隔	 
        /// </summary>
        public string actors
        { get; set; }

        /// <summary>
        ///	参与状态1 已报名 0未报名  针对“志愿活动”类型新增的字段
        /// </summary>
        public string act_status
        { get; set; } 
    }
    #endregion 
}